package com.shoulder.boot.demo.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shoulder.boot.demo.dto.DemoAddDTO;
import com.shoulder.boot.demo.dto.DemoModDTO;
import com.shoulder.boot.demo.dto.DemoQueryDTO;
import com.shoulder.boot.demo.service.Demo2Service;
import com.shoulder.boot.demo.service.DemoService;
import com.shoulder.boot.demo.vo.DemoVo;
import com.shoulder.core.annotation.Anonymous;
import com.shoulder.core.api.ApiResult;
import com.shoulder.core.fetch.BaseIds;
import com.shoulder.core.page.PageSchema;
import com.shoulder.log.annotation.LogAnnotation;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 样例信息管理
 */
@RestController
@AllArgsConstructor
@RequestMapping("/admin/api/v1/demo/demo")
public class DemoController {

    private final DemoService demoService;
    private final Demo2Service demo2Service;

    /**
     * 添加样例信息
     *
     * @param addDTO 样例信息添加请求体
     * @return ApiResult<Object>
     * @author 596767880@qq.com
     */
    @PostMapping
    @LogAnnotation(type = "添加样例信息")
    public ApiResult<Object> add(@RequestBody @Validated DemoAddDTO addDTO) {
        this.demoService.add(addDTO);
        return ApiResult.ok();
    }

    /**
     * 修改样例信息
     *
     * @param modDTO 样例信息修改请求体
     * @return ApiResult<Object>
     * @author 596767880@qq.com
     */
    @PutMapping
    @LogAnnotation(type = "修改样例信息")
    public ApiResult<Object> mod(@RequestBody @Validated DemoModDTO modDTO) {
        this.demoService.mod(modDTO);
        return ApiResult.ok();
    }

    /**
     * 查询样例信息分页数据
     *
     * @param queryDTO 样例信息查询请求体
     * @return 样例信息分页数据
     * @author 596767880@qq.com
     */
    @LogAnnotation(type = "样例信息分页查询", record = false)
    @PostMapping("/page")
    public ApiResult<PageSchema<DemoVo>> pageQuery(@RequestBody DemoQueryDTO queryDTO) {
        Page<DemoVo> page = this.demoService.pageQuery(queryDTO);
        return ApiResult.ok(new PageSchema<>(page.getTotal(), page.getRecords()));
    }

    /**
     * 查询样例信息列表数据
     *
     * @param queryDTO 样例信息查询请求体
     * @return 样例信息列表数据
     * @author 596767880@qq.com
     */
    @LogAnnotation(type = "样例信息列表查询", record = false)
    @PostMapping("/list")
    public ApiResult<List<DemoVo>> list(@RequestBody DemoQueryDTO queryDTO) {
        List<DemoVo> list = this.demoService.listQuery(queryDTO);
        return ApiResult.ok(list);
    }

    /**
     * 批量删除样例信息
     *
     * @param baseIds 样例信息id集合
     * @return ApiResult<Object>
     * @author 596767880@qq.com
     */
    @PostMapping("/rm")
    @LogAnnotation(type = "批量删除样例信息")
    public ApiResult<Object> delete(@RequestBody @Validated BaseIds<String> baseIds) {
        this.demoService.batchDel(baseIds);
        return ApiResult.ok();
    }


    /**
     * 根据id删除样例信息
     *
     * @param id 样例信息id
     * @return ApiResult<Object>
     * @author 596767880@qq.com
     */
    @DeleteMapping("/{id}")
    @LogAnnotation(type = "删除样例信息")
    public ApiResult<Object> del(@PathVariable String id) {
        this.demoService.del(id);
        return ApiResult.ok();
    }


    /**
     * 批量查询样例信息
     *
     * @param baseIds 样例信息id集合
     * @return 样例信息列表数据
     * @author 596767880@qq.com
     */
    @PostMapping("/look")
    @LogAnnotation(type = "批量查询样例信息", record = false)
    public ApiResult<List<DemoVo>> looks(@RequestBody BaseIds<String> baseIds) {
        List<DemoVo> list = this.demoService.looks(baseIds);
        return ApiResult.ok(list);
    }

    /**
     * 根据id获取样例信息
     *
     * @param id 样例信息id
     * @return 样例信息
     * @author 596767880@qq.com
     */
    @GetMapping("/{id}")
    @LogAnnotation(type = "根据id查询样例信息", record = false)
    public ApiResult<DemoVo> look(@PathVariable String id) {
        DemoVo look = this.demoService.look(id);
        return ApiResult.ok(look);
    }

    @Anonymous
    @LogAnnotation(type = "样例信息列表权限测试", record = false)
    @GetMapping("/test")
    public ApiResult<List<DemoVo>> test() {
        List<DemoVo> list = this.demo2Service.demoTest();
        return ApiResult.ok(list);
    }

}